Always will expose native Promise
if available, otherwise Bluebird
but only if you don't give another promise module like q
or promise
or what you want.
Heads up: v3 is here! See the changelog.md
Install
npm i native-or-another --save
Usage
For more use-cases see the tests
const getPromise = require('native-or-another')
Always will expose native Promise
if available. Otherwise given promise module or Bluebird.
[Prome]
{Function} custom promise modulereturns
{Function} native Promise or another
Example
const fs = require('fs')
const NativeOrBluebird = getPromise()
const NativeOrPromise = getPromise(require('promise'))
const NativeOrPinkie = getPromise(require('pinkie'))
const NativeOrQ = getPromise(require('q'))
const promise = new NativeOrBluebird((resolve, reject) => {
fs.readFile('package.json', 'utf-8', (err, res) => {
if (err) return reject(err)
resolve(res)
})
})
promise.then(data => {
console.log(JSON.parse(data).name)
})
Related
- always-done: Handles completion and errors of anything!
- always-promise: Promisify basically everything.
- always-thunk: Create thunk from anything, works like
thunkify
. Transforms anything (callbacks, streams, promises, observables, child processes, sync and generator functions) to thunk. - redolent: Simple promisify a callback-style function with sane defaults.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.